qui(
    function (require, exports, module) {
        VOD.Evt = {
            InitBindEvt: function () {
                // 显示小窗口视频预览
                var playOneInfo = VOD.Dao.playOneInfo;
                $("#makedImg").on("mouseenter mouseleave", "img", function (event) {
                    var self = $(this);
                    if (event.type == 'mouseenter') {
                        playOneInfo.mouseenter = true;
                        playOneInfo.left = self.offset().left - $("#play-one").width();
                        playOneInfo.top = self.offset().top;
                        playOneInfo.time = self.attr("id").split("-")[1];
                    } else if (event.type == 'mouseleave') {
                        playOneInfo.mouseenter = false;
                        $("#play-one").css({
                            top: '-1000px',
                            left: '-1000px'
                        });
                    }
                });
                $(".cVideo").click(function () {
                    if ($(this).attr('data') == 'cover-program') {
                        $("#cover-program-cfm").show();
                    } else {
                        $("#cover-program-cfm").hide();
                    }
                });
                $('#ase-close').on('click', function () {
                    VOD.AccurateFrame.accurateStartEndRemove()
                });
            },
            // 显示和隐藏打点打条列表
            ShowAndHideSegmentationList: function () {
                var list = $(".segmentation").find(".list");
                if (list.attr("data-show") == "false") {
                    list.show();
                    list.attr("data-show", "true");
                    $(".title").find(".glyphicon").addClass("glyphicon-chevron-down");
                    $('#list-slide-shrink').text('收起');
                } else {
                    list.hide();
                    list.attr("data-show", "false");
                    $(".title").find(".glyphicon").removeClass("glyphicon-chevron-down");
                    $('#list-slide-shrink').text('展开');
                }
            },

            // 打开关闭背景颜色
            OpenOrCloseBk: function (self) {
                if (!self.hasClass("switch-position")) {
                    self.addClass("switch-position");
                    VOD.Dao.storageData('BCS', 'on');
                    $('.fragment-img').removeClass('c000');
                    $('.in-out-mark-s').show();
                } else {
                    self.removeClass("switch-position");
                    VOD.Dao.storageData('BCS', 'off');
                    $('.fragment-img').addClass('c000');
                    $('.in-out-mark-s').hide();
                }
            },

            SelectAll: function (self) {
                if (self.is(':checked'))

                    $.each($(".tab-content input[type='checkbox']"), function () {

                        if (!$(this).attr('readOnly'))
                            $(this).prop('checked', true);

                    });
                else
                    $(".tab-content input[type='checkbox']").prop('checked', false);
            },

            CheckedSegId: function (self) {
                var $tr = self.parents("tr"),
                    options = {};

                options.st = $tr.find('[name$="sTime"]').val();
                options.et = $tr.find('[name$="eTime"]').val();
                options.color = "c09f";
                if (!options.st)
                    return;

                if (self.is(":checked")) {
                    fromLIstJump(options.st);
                    VOD.Util.addBackgroundColor(options);
                } else {
                    options.removeColor = true;
                    VOD.Util.addBackgroundColor(options);
                }

            },

            // 合并已选拆条
            SubAllMerge: function () {
                var merg = {
                        range: '',
                        imageId: '',
                        sTime: '',
                        eTime: '',
                        albumName: '',
                        albumId: '',
                        videoName: ''
                    },
                    $check = $("#tab2").find('[action-name="checked-seg-id"]:checked');
                len = $check.length;

                if (len > 0) {
                    var sTime,
                        eTime
                    mergData = [];

                    $.each($check, function (i, item) {

                        var $parent = $(this).parents('.inner-table'),
                            st = $parent.find('[name$="sTime"]').val(),
                            et = $parent.find('[name$="eTime"]').val(),
                            seg = '';

                        if (!merg.sTime) {
                            merg.sTime = st;
                            merg.albumName = $parent.find('[name$="albumName"]').val();
                            merg.albumId = $parent.find('[name$="albumId"]').val();
                            merg.videoName = $parent.find('[name$="videoName"]').val();
                            merg.categoryId = $parent.find('[name$="categoryId"]').val();
                        }

                        eTime = et;

                        $(this).trigger('click');

                        if (i < len - 1)
                            seg = ',';

                        merg.range = merg.range + $(this).val() + '(' + st + '-' + et + ')' + seg;
                        mergData.push(st + '_' + et);

                        if (!merg.imageId)
                            merg.imageId = st;
                    });

                    merg.eTime = eTime;
                    merg.mergData = mergData;

                    VOD.Util.appendMergeSeg(merg);

                    $('[action-name="merge-segmentation-tab"]').trigger('click');
                    //console.log(merg);
                    $('[data-id="' + merg.sTime + '"]').val(merg.categoryId);

                    $('.merg-seg-tips').hide();
                } else
                //alert('请选择要合并项');
                    VOD.Plugin.tips("error", '请选择要合并项');
            },

            // 提交已选择所有拆条
            SubAllSeg: function () {

                if (VOD.Dao.settings.taskid < 1) {
                    //alert('任务ID为空,不能提交!');
                    VOD.Plugin.tips("error", '任务ID为空,不能提交!');
                    return false;
                }

                var $check = $("#tab2").find('[action-name="checked-seg-id"]:checked'),
                    len = $check.length;

                if (len > 0) {
                    $.each($check, function (i, item) {
                        var $parent = $(this).parents('.inner-table');
                        //console.log($(this).val());
                        //$(this).trigger('click');
                        VOD.Evt.SubAutoSeg($parent.find('[action-name="sub-seg"]'));
                    });
                } else
                //alert('请选择要提交的拆条');
                    VOD.Plugin.tips("error", '请选择要提交的拆条');
            },

            // 提交已选择所有广告
            SubAllAd: function () {
                var $check = $("#tab2").find('[action-name="checked-seg-id"]:checked'),
                    len = $check.length;

                if (len > 0) {
                    $.each($check, function (i, item) {
                        var $parent = $(this).parents('.inner-table');

                        $(this).trigger('click');
                        VOD.Evt.SubAutoAd($parent.find('[action-name="sub-ad"]'));
                    });
                } else
                //alert('请选择要提交的广告');
                    VOD.Plugin.tips("error", '请选择要提交的广告');
            },
// 自动拆条input操作时添加背景色

            // 定时提醒
            RegularTimeRemind: function () {
                var regularTime = $("#alert-time").val();

                if (regularTime && regularTime != "undefined") {
                    (function () {
                        var compareTimeRt = -1, //时间比较结果
                        //blinkTimes = 0,     //闪烁次数
                        //settedTime = '',
                            isTimeArriveInt = null;
                        $("#alert-pop").attr("disabled", "disabled");

                        //alert("添加成功");
                        VOD.Plugin.tips("success", '添加成功');

                        var isTimeArrive = function () {
                            var time = $("#alert-time").val();
                            var now = new Date();
                            var nowStr = VOD.Util.formatDateTimeFormat(now);
                            compareTimeRt = VOD.Util.compareTime(time, nowStr);
                        };

                        var titleWink = function () {
                            // blinkTimes++;
                            //if(blinkTimes==3){blinkTimes=1}

                            if (compareTimeRt >= 0) {
                                window.focus();
                                alert('【' + VOD.Dao.getParamsData().channel_name + '】【' + regularTime + '】预定时间已到!');
                                $("#alert-pop").removeAttr("disabled");
                                $("#alert-time").val("");
                                clearInterval(isTimeArriveInt);
                                return;
                            }
                            setTimeout(titleWink, 200);
                        };

                        isTimeArriveInt = setInterval(isTimeArrive, 200);
                        //settedTime = time;
                        titleWink();

                    })();
                } else {
                    //alert("时间不能为空");
                    VOD.Plugin.tips("error", '时间不能为空');
                }
            },

            // 提交广告智能入库
            saveAdLibrary: function (targetElement) {
                var settings = VOD.Dao.settings;
                var taskid = settings.taskid;
                if (taskid < 1) {
                    //alert('任务ID为空,不能提交!');
                    VOD.Plugin.tips("error", '任务ID为空,不能提交!');
                    return false;
                }

                var options = {};

                if (settings.delList.length === 0) {
                    VOD.Plugin.tips("error", '广告列表数据不能为空！');
                    return false;
                }
                var params = VOD.Dao.getParamsData();
                options.list = '[' + settings.delList.join(',') + ']';

                options.key = taskid;
                options.channelId = params._channel_id;
                options.offsets = VOD.AccurateFrame.getAdAccurate();  // 广告精确化

                if (!options.channelId.length) {
                    //alert('频道ID为空,不能提交!');
                    VOD.Plugin.tips("error", '频道ID为空,不能提交!');
                    return false;
                }

                options.ablumId = $('input[name=albumName]').suggest("getValue");
                if (!options.ablumId.length) {
                    //alert('专辑ID为空,不能提交!');
                    VOD.Plugin.tips("error", '专辑ID为空,不能提交!');
                    return false;
                }

                VOD.Dao.saveAdLibrary(options, function (data) {

                    if (data.error != 0) {
                        //alert(erroNo + '' + data.error);
                        VOD.Plugin.tips("error", "广告入智能库失败！");
                        targetElement.removeClass("disabled");
                    }
                    else {
                        //alert("广告入智能库提交成功！");
                        VOD.Plugin.tips("success", "广告入智能库提交成功！");
                        targetElement.removeClass("disabled");
                        //adLibList = [];
                    }
                });
            },

            // 提交专辑智能入库
            saveAlbumLibrary: function (targetElement) {
                var options = {};

                var taskid = VOD.Dao.settings.taskid;
                if (taskid < 1) {
                    //alert('任务ID为空,不能提交!');
                    VOD.Plugin.tips("error", '任务ID为空,不能提交!');
                    return false;
                }

                var sTime = $('input[name=sTime]').val(),
                    eTime = $('input[name=eTime]').val();
                if (isNaN(sTime) || !sTime) {
                    //alert('起始帧有误,必须为数字类型');
                    VOD.Plugin.tips("error", '起始帧有误,必须为数字类型');
                    return false;
                }
                if (isNaN(eTime) || !eTime) {
                    //alert('结束帧有误,必须为数字类型');
                    VOD.Plugin.tips("error", '结束帧有误,必须为数字类型');
                    return false;
                }

                var acrossTtime = eTime - sTime;
                var genList = function (head, end, n) {
                    var list = {};
                    list.head = [head];
                    list.end = [end];
                    n = n - 1;
                    if (n >= 6) {
                        n = 6;
                    }
                    for (var i = 1; i <= n; i++) {
                        list.head.push(head + i);
                    }
                    for (var j = 1; j <= n; j++) {
                        list.end.unshift(end - j);
                    }
                    list.head = '[' + list.head.join(',') + ']';
                    list.end = '[' + list.end.join(',') + ']';
                    return list;
                }

                options.list = genList(parseInt(sTime), parseInt(eTime), acrossTtime);

                options.key = taskid;

                options.ablumId = $('input[name=albumName]').suggest("getValue");
                if (!options.ablumId.length) {
                    //alert('专辑ID为空,不能提交!');
                    VOD.Plugin.tips("error", '专辑ID为空,不能提交!');
                    return false;
                }
                var frameData = VOD.AccurateFrame.getAccurateFrame()
                if (!frameData.headSetted) {
                    frameData.head = 0;
                }

                if (!frameData.endSetted) {
                    frameData.end = 0;
                }

                options.offset = {'head': frameData.head, 'end': frameData.end}
                options.channelId = VOD.Dao.getParamsData()._channel_id;
                if (!options.channelId.length) {
                    VOD.Plugin.tips("error", '频道ID为空,不能提交!');
                    return false;
                }

                targetElement.addClass("disabled");

                VOD.Dao.saveAlbumLibrary(options, function (data) {
                    if (data.error != 0) {
                        VOD.Plugin.tips("error", data.error);
                        targetElement.removeClass("disabled");
                    }
                    else {
                        VOD.Plugin.tips("success", "专辑入智能库提交成功！");
                        targetElement.removeClass("disabled");
                    }
                });
            },
            setVideoName: function () {
                var val = $('input:radio[name="optionsRadios"]:checked').parent().text();
                VOD.Config.Global.statisticOcrTitle = val;
                $("input[name=videoName]").val(val);
                $("input[name=videoName]").attr("eut", $('input:radio[name="optionsRadios"]:checked').val());
            },
            setOcrTitleList: function () {
                var s_sTime = $('input[name=sTime]').val();
                var s_eTime = $('input[name=eTime]').val();
                if (s_sTime == "undefined" || s_sTime == "" || s_eTime == "undefined" || s_eTime == "") {
                    $("#ocr-detail").html("<div style=\"color:grey;height:150px;\">起始结束帧不能为空！</div>");
                    return;
                }
                var tmp = VOD.Util.binSearchOcrTitle(s_sTime, s_eTime);
                if (tmp == '') {
                    $("#ocr-detail").html("<div style=\"color:grey;height:150px;\">没有识别到的标题！</div>");
                    return;
                }

                var checkboxHtml = '';
                var k = 1;

                var outTmp = $("input[name=videoName]").attr("eut");
                var eut = '';
                var ck = "";
                for (var i in tmp) {

                    if (outTmp != '') {
                        eut = encodeURIComponent(tmp[i]);
                        if (outTmp == eut) {
                            ck = 'checked';
                        } else {
                            ck = '';
                        }
                    } else {
                        if (k == 1)
                            ck = 'checked';
                        else
                            ck = '';
                        k++;
                    }

                    checkboxHtml += '<div class="radio">'
                        + '<label  ondblclick="VOD.Evt.setVideoDesc()">'
                        + '<input type="radio" name="optionsRadios" value="' + eut + '" ' + ck + '>'
                        + tmp[i]
                        + '</label>'
                        + '</div>';
                }

                $("#ocr-detail").html(checkboxHtml);
            },
            setAcrTitleList: function () {
                var s_sTime = $('input[name=sTime]').val();
                var s_eTime = $('input[name=eTime]').val();

                if (s_sTime == "undefined" || s_sTime == "" || s_eTime == "undefined" || s_eTime == "") {
                    $("#acr-detail").html("<div style=\"color:grey;height:150px;\">起始结束帧不能为空！</div>");
                    return;
                }

                var tmp = VOD.Util.binSearchAcrTitle(s_sTime, s_eTime);
                if (tmp == '') {
                    $("#acr-detail").html("<div style=\"color:grey;height:150px;\">没有识别到描述！</div>");
                    return;
                }
                var checkboxHtml = '';
                var k = 1;
                var eut = '';
                var ck = "";
                var outTmp = $("textarea[name=desc]").attr("eut");

                for (var i in tmp) {

                    eut = encodeURIComponent(tmp[i]);
                    if (outTmp != '') {
                        var f = new RegExp(eut, 'gi');
                        if (f.test(outTmp)) {
                            ck = 'checked';
                        } else {
                            ck = '';
                        }
                    } else {
                        if (k == 1)
                            ck = 'checked';
                        else
                            ck = '';
                        k++;
                    }

                    checkboxHtml += '<div class="checkbox">'
                        + '<label  ondblclick="VOD.Evt.setVideoDesc()">'
                        + '<input type="checkbox" name="optionsCheckboxs" value="' + eut + '" ' + ck + '>'
                        + tmp[i]
                        + '</label>'
                        + '</div>';
                }

                $("#acr-detail").html(checkboxHtml);
            },
            setVideoDesc: function () {
                var val = '';
                var var2 = '';
                var val1 = $('input:checkbox[name="optionsCheckboxs"]:checked');
                $.each(val1, function (i, n) {
                    val += $(n).parent().text();
                    var2 += $(n).val();
                });
                $("textarea[name=desc]").val(val);
                $("textarea[name=desc]").attr("eut", var2);
            }
        };

    }
);